﻿Public Class VACCINEDURATION
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Public Sub queryVacdurationGrid()
        Dim objVacdurationGrid As New VACDURATIONCLASS
        Dim dt As DataTable = connect.GetTable(objVacdurationGrid.selectVacduration_)
        vacdurationGrid.PrimaryGrid.DataSource = dt
    End Sub

    Private Sub clearForm()
        VDIDTxt.Clear()
        VACCINEIDTxt.Clear()
        CNOTxt.Text = ""
        SPANTxt.Text = ""
        MAXSPANTxt.Text = ""
        vacdurationStatusChk.Checked = False
    End Sub

    '-----filter----------
    Private Sub filterVaccineName()
        Dim s As FILTERCLASS
        Dim sql As String = "SELECT CAST(vaccineid AS CHAR(4)) AS VACCINEID, vaccine_th, vaccine_en, vaccode FROM myfriendsdb.masvaccine WHERE (`status` = 1);"
        s = New FILTERCLASS(VACCINEIDTxt, sql, "รหัสวัคซีน,ชื่อวัคซีน,ชื่อวัคซีน(Eng),Codeวัคซีน", "50,140,140,80", "1,1,1,1", "1,1,1,1")
        s.SetShowInDown = True
        s.SetShowBorder = True
    End Sub

    Private Sub VACCINEDURATION_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        queryVacdurationGrid()
        filterVaccineName()

        DesignForm(Me)
        DesignGrid(vacdurationGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub vacdurationGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles vacdurationGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID").Value() IsNot DBNull.Value Then
            VDIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID").Value()
        Else
            VDIDTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสวัคซีน").Value() IsNot DBNull.Value Then
            VACCINEIDTxt.Tag = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสวัคซีน").Value()
            VACCINEIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อไทย").Value()
        Else
            VACCINEIDTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ลำดับเข็ม").Value() IsNot DBNull.Value Then
            CNOTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ลำดับเข็ม").Value()
        Else
            CNOTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("อายุที่ฉีด").Value() IsNot DBNull.Value Then
            SPANTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("อายุที่ฉีด").Value()
        Else
            SPANTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("อายุที่ฉีดสูงสุด").Value() IsNot DBNull.Value Then
            MAXSPANTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("อายุที่ฉีดสูงสุด").Value()
        Else
            MAXSPANTxt.Text = ""
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            vacdurationStatusChk.Checked = True
        Else
            vacdurationStatusChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("vacduration", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "VDID", VDIDTxt.Text)
    End Sub

    Private Sub addVacduration_Click(sender As Object, e As EventArgs) Handles addVacduration.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If VACCINEIDTxt.Text.ToString.Length > 0 And CNOTxt.Text.Length.ToString > 0 And SPANTxt.Text.Length.ToString > 0 And MAXSPANTxt.Text.Length.ToString > 0 Then
                    Dim objInsertData As New VACDURATIONCLASS
                    objInsertData.VACCINEID_ = VACCINEIDTxt.Tag
                    objInsertData.CNO_ = CNOTxt.Text
                    objInsertData.SPAN_ = SPANTxt.Text
                    objInsertData.MAXSPAN_ = MAXSPANTxt.Text
                    objInsertData.STATUS_ = vacdurationStatusChk.Checked

                    If objInsertData.insertVacduration = True Then
                        MsgBox("ท่านได้ทำการเพิ่มข้อมูลระยะเวลาการฉีดวัคซีนเรียบร้อยแล้ว")
                        queryVacdurationGrid()
                        clearForm()
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editVacduration_Click(sender As Object, e As EventArgs) Handles editVacduration.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If VDIDTxt.Text.Length.ToString > 0 And VACCINEIDTxt.Text.ToString.Length > 0 And CNOTxt.Text.Length.ToString > 0 And SPANTxt.Text.Length.ToString > 0 And MAXSPANTxt.Text.Length.ToString > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลเวลาการฉีดวัคซีนดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New VACDURATIONCLASS
                        objEditData.VDID_ = VDIDTxt.Text
                        objEditData.VACCINEID_ = VACCINEIDTxt.Tag
                        objEditData.CNO_ = CNOTxt.Text
                        objEditData.SPAN_ = SPANTxt.Text
                        objEditData.MAXSPAN_ = MAXSPANTxt.Text
                        objEditData.STATUS_ = vacdurationStatusChk.Checked

                        If objEditData.editVacduration = True Then
                            MsgBox("ท่านได้ทำการแก้ไขข้อมูลระยะเวลาการฉีดวัคซีนเรียบร้อยแล้ว")
                            queryVacdurationGrid()
                            clearForm()
                        End If
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("vacduration")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("vacduration")
        nextform.ShowDialog()
    End Sub

    
    
    
End Class